Checking
PDH Return Values
The return
value of PDH functions indicates the success or error of the function call,
which is distinct from the status of the counter data. Always check the CStatus
member of a counter value returned in the PDH structures to ensure that the data
returned is valid before you use it. If the value of the CStatus member
does not indicate success, do not use the data. The following are the possible
status values for counters:
PDH_CSTATUS_NO_MACHINE
PDH was
unable to connect to the machine specified in the counter path. If this status
is returned when the counter is being added, the counter is not completely
initialized. Each time the query is updated, PDH retries the connection. When
the connection is established, normal data collection resumes.
PDH_CSTATUS_NO_OBJECT
The specified
machine was found, but no matching performance object was found on that
machine. If this status is returned when the counter is being added, the
specified counter is not included in the query. If this status is returned by
an active counter, the data for that counter is invalid. Each time the data is
requested, PDH tries to obtain this counter data.
PDH_CSTATUS_NO_INSTANCE
The specified
instance was not found in the object. If this status is returned while the
counter is being added to the query, the counter is successfully added to the
query, but no data is available until the specific instance appears and a
successful status is returned.
PDH_CSTATUS_NO_COUNTER
The specified
counter was not found in the specified object. If this status is returned when
the counter is being added, then the counter is not added to the query. If this
status is returned after a data update, the data for that counter is invalid.
Each time the data is requested, PDH tries to obtain this counter data.
PDH_CSTATUS_INVALID_DATA
The counter
was successfully found, but the data returned is not valid. One possible cause
for this value is when the data of a normally increasing counter is less than
the previous value. Another possible cause is a system timer that is not
correct.
PDH_CSTATUS_VALID_DATA
The data for
the counter was returned successfully, but is unchanged from the last time the
counter was read.
PDH_CSTATUS_NEW_DATA
The data for
the counter was returned successfully and is different from the last time the
counter was read. PDH_CSTATUS_NEW_DATA can be returned on a rate counter even
if the resulting rate is the same as the last sample. This is because the raw
data value that is used in the determination of this status value has changed,
not the computed rate.
PDH_CSTATUS_NO_COUNTERNAME
No counter path
was specified.
PDH_CSTATUS_BAD_COUNTERNAME
The counter
path format is incorrect.